ZF.add('native-string', function(Z) {

    Z.String = {

        substitute : function(str, object, regexp){
            return str.replace(regexp || (/\\?\{([^}]+)\}/g), function(match, name){
                if (match.charAt(0) == '\\') return match.slice(1);
                return (object[name] != undefined) ? object[name] : '';
            });
        },
        
        stripScripts : function(str, exec) {
            var scripts = '',
                text = str.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(all, code){
                    scripts += code + '\n';
                    return '';
                });
            
            if (exec) {
                Z.Browser.exec(scripts);
            } else if (ZF.Lang.isFunction(exec)) {
                exec(scripts, text);
            }

            return text;
        },
        
        contains : function(str, string, separator){
            return (separator) ? (separator + str + separator).indexOf(separator + string + separator) > -1 : str.indexOf(string) > -1;
        },

        trim: function(str){
            return str.replace(/^\s+|\s+$/g, '');
        },

        clean: function(str){
            return this.trim(str.replace(/\s+/g, ' '));
        },
        
        escHtml : function(str, exceptBR){
            return (exceptBR === true ? str.replace(/<br\s*\/?>/gi, '\n') : str).replace(/[&'"<>\/\\\-\x00-\x09\x0b-\x0c\x1f\x80-\xff]/g, function(r){return "&#"+r.charCodeAt(0)+";";}).replace(/\r\n/g, "<br/>").replace(/\n/g, "<br/>").replace(/\r/g, "<br/>").replace(/ /g, "&nbsp;");
        },
        
        escHtmlEp : function(str){
            return str.replace(/[&'"<>\/\\\-\x00-\x1f\x80-\xff]/g, function(r){ return "&#"+r.charCodeAt(0)+";" });
        },
        
        /**
         * 获取指定偏移的字符串
         * 
         * @param
         * 		str		String	源字符串
         * 		begin	Integer	偏移开始位置
         * 		end		Integer	偏移结束位置
         */
        between : function(str, begin, end) {
            var bp = str.indexOf(begin);

            if (bp == -1) {
                return '';
            }

            bp += begin.length;
            
            var ep = str.indexOf(end, bp);

            if (ep == -1) {
                return '';
            }

            return str.substr(bp, ep - bp);
        },
        
        capitalize : function(str){
            return str.replace(/\b[a-z]/g, function(match){
                return match.toUpperCase();
            });
        }

    }

});
